<?php
declare (strict_types = 1);

namespace app\api\validate;

use think\Validate;

class User extends Validate
{
    protected $scene = [
        'send_code' => ['phone'],
        'login'     => ['phone', 'code', 'type'],
        'update'    => ['username', 'sex', 'operate_user'],
    ];

    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'username' => 'require',
        'phone'    => 'require',
        'code'     => 'require|number|min:6',
        'type'     => 'require|number|in:1,2',
        'sex'      => 'require|in:0,1,2',
        'operate_user' => 'require'
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'username.require' => '用户名不能为空',
        'phone.require'    => '电话不能为空',
        'code.require'     => '验证码不能为空',
        'code.number'      => '验证码格式错误',
        'code.min'         => '验证码长度错误',
        'type.require'     => '类型不能为空',
        'type.number'      => '类型格式错误',
        'type.in'          => '类型数据错误',
        'sex.require'      => '性别不可为空',
        'sex.in'           => '性别数值错误',
        'operate_user.require' => '操作人不可为空'
    ];
}
